import request from "@/request";
import { AxiosResponse } from "axios";
import ResultEnum from "@/config/ResultEnum";
import { message } from "ant-design-vue";

export const statusOptions = [
  {
    label: "正常",
    value: "Normal",
    color: "#2db7f5",
  },
  {
    label: "禁用",
    value: "Disable",
    color: "#87d068",
  },
];

export const requestMethodOptions = [
  { label: "GET", value: "GET" },
  { label: "POST", value: "POST" },
  { label: "DELETE", value: "DELETE" },
  { label: "PATCH", value: "PATCH" },
  { label: "PUT", value: "PUT" },
];

//表格列
export const tableCols = [
  {
    title: "#",
    dataIndex: "idx",
    key: "idx",
    width: 50,
  },
  {
    title: "请求方式",
    dataIndex: "requestMethod",
    key: "requestMethod",
    width: 100,
  },
  {
    title: "地址",
    key: "url",
  },
  {
    title: "接口",
    dataIndex: "apiName",
    key: "apiName",
    width: 250,
  },
  {
    title: "耗时(毫秒)",
    key: "usedTime",
    dataIndex: "usedTime",
    width: 100,
  },
  {
    title: "创建时间",
    key: "createdTime",
    dataIndex: "createdTime",
  },
  {
    title: "操作",
    width: 100,
    key: "actions",
    fixed: "right",
  },
];

export const getApiOptions = () => {
  return new Promise((resolve: any, reject: any) => {
    request({
      url: "/common/wechat/api/request/options",
      method: "get",
    }).then((res: any) => {
      if (res.code == ResultEnum.SUCCESS_CODE) {
        resolve(res.result);
      } else {
        message.error(res.message);
      }
    });
  });
};

//获取数据
export const loadTable = (params: any) => {
  return new Promise((resolve: any, reject: any) => {
    request({
      url: "/wxRequestLog/list",
      method: "get",
      params,
    }).then((res: any) => {
      if (res.code == ResultEnum.SUCCESS_CODE) {
        resolve(res.result);
      } else {
        message.error(res.message);
      }
    });
  });
};
